// 组装render

export const columnDataTranform = arr => {
  arr.forEach(v => {
    v.label = v.title;
    if (v.selectOptions) {
      v.render = data => {
        let val = data.record[v.dataIndex];
        if (val instanceof Array) {
          return val.reduce(
            (a, b) => a + b[v.options?.label || 'value'] + ',',
            ''
          );
        } else {
          return v.selectOptions.find(
            v => v[v.options?.label || 'value'] === val
          )?.[v.options?.value || 'label'];
        }
      };
      v.renderView = val => {
        if (val instanceof Array) {
          return val.reduce(
            (a, b) => a + b[v.options?.label || 'value'] + ',',
            ''
          );
        } else {
          return v.selectOptions.find(
            v => v[v.options?.label || 'value'] === val
          )?.[v.options?.value || 'label'];
        }
      };
    }
  });

  return arr;
};
